home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Library
/
RoseWare - Network Support Library.iso
/
apidev
/
mhs_c.arc
/
OUTPOST.ARC
/
OPENFILE.C
< prev
next >
Wrap
C/C++ Source or Header
|
1988-06-27
|
2KB
|
78 lines
/* ****************************** OPENFILE.C ****************************** */
#include "cctypes.h"
extern int InFile;
extern int OutFile;
extern char InFileName[];
extern char OutFileName[];
extern char InExtension[];
int OpenInputFile() /* the file created by XRBoxOut */
{
char *p;
int returnCode = NO_ERROR;
/* check for illegal extensions */
p = strrchr(InFileName,'.');
if ( p != NULL ) {
if ( strcmp(p,InExtension) != 0 ) {
/* Error(INVALID_FILENAME); */
returnCode = -1;
goto Out;
}
}
/* open the input file (read) */
InFile = open(InFileName, O_RDONLY | O_RAW, 0);
if ( (InFile == -1) &&
(strchr(&InFileName[strlen(InFileName) - 4], '.') == NULL ))
{
/* add the extension if not already there */
strcat(InFileName, InExtension);
InFile = open(InFileName, O_RDONLY | O_RAW, 0);
}
if ( InFile == -1 )
returnCode = -1;
Out:
return(returnCode);
}
int OpenOutputFile(extension) /* the file to be IMPORTed into CC:MAIL */
char *extension;
{
int returnCode = NO_ERROR;
char *p;
FILE *tempHandle;
/* make the output (MCB) file in the same directory */
strcpy(OutFileName,InFileName);
Again:
p = strrchr(OutFileName,'.');
if ( p == NULL ) {
strcat(OutFileName,".");
goto Again;
}
strcpy(p,extension);
tempHandle = fopen(OutFileName, "r");
if ( tempHandle != NULL ) {
/* already exists */
fclose(tempHandle);
unlink(OutFileName); /* it should do this already if using 0x8301 below */
}
/* open/create the MCB file for writing */
OutFile = open(OutFileName, 0x8301, 0);
if ( OutFile == -1 ) {
Error(CANNOT_CREATE_OUTPUT);
goto CantDo;
}
goto Out;
CantDo:
returnCode = CANNOT_CREATE_OUTPUT;
Out:
return(returnCode);
}